/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduleManager;

import app.Global;
import entities.EmployeeSchedule;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import lib.JButtonTable.ButtonEditor;

/**
 *
 * @author yoshi
 */
public class RequestButtonEditor extends ButtonEditor {

    public RequestButtonEditor(JCheckBox checkBox, final AbstractScheduleManager myView) {
        super(checkBox);
        
        final RequestButtonEditor self = this;
        
        this.button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new Thread() {

                    @Override
                    public void run() {
                        RequestButtonModel buttonModel = (RequestButtonModel) (self.getCellEditorValue());
                        ShiftRequestDialog shiftRequestDialog = new ShiftRequestDialog(Global.getFrame(), true, myView, buttonModel.getSchedule());
                    }
                }.start();
            }
        });
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        button.setText(((RequestButtonModel) value).getText());
        return super.getTableCellEditorComponent(table, value, isSelected, row, column);
    }

    @Override
    public boolean isCellEditable(EventObject anEvent) {
        boolean result = false;
        try{
            EmployeeSchedule schedule = (EmployeeSchedule) (this.getCellEditorValue());
        }catch(Exception e){
            
        }
        return super.isCellEditable(anEvent);
    }
    
}
